package com.atguigu.crowd.constant;

import java.util.HashSet;
import java.util.Set;

public class AccessPassResources {

    public static final Set<String> PASS_RES_SET=new HashSet<>();

    static {
        PASS_RES_SET.add("/");
        PASS_RES_SET.add("/auth/to/member-reg.html");
        PASS_RES_SET.add("/auth/to/member/login/page");
        PASS_RES_SET.add("/auth/member/logout");
        PASS_RES_SET.add("/auth/member/do/login");
        PASS_RES_SET.add("/auth/do/member/register");
        PASS_RES_SET.add("/auth/member/send/short/message.json");
    }

    public static final Set<String> STATIC_RES_SET=new HashSet<>();

    static {
        STATIC_RES_SET.add("bootstrap");
        STATIC_RES_SET.add("css");
        STATIC_RES_SET.add("fonts");
        STATIC_RES_SET.add("img");
        STATIC_RES_SET.add("jquery");
        STATIC_RES_SET.add("layer");
        STATIC_RES_SET.add("script");
        STATIC_RES_SET.add("ztree");
    }

    /**
     * 判断servletPath的值是否为静态资源
     * @param servletPath
     * @return
     */
    public static boolean judgeCurrentServletPathWetherStaticResource(String servletPath){
        //判断字符串是否有效
        if (servletPath==null || servletPath.length()==0){
            throw new RuntimeException(CrowdContant.MESSAGE_STRING_INVALIDATE);
        }
        String[] split = servletPath.split("/");

        String firstLevelPath=split[1];

        return STATIC_RES_SET.contains(firstLevelPath);
    }

//    public static void main(String[] args) {
//        String path="/css/askhd";

//        String[] split = path.split("/");
//
//        for (String s:split) {
//            System.out.println(s);
//        }

//        boolean b = judgeCurrentServletPathWetherStaticResource(path);
//
//        System.out.println(b);
//    }


}
